package com.its.equipment.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.its.domain.BaseResult;
import com.its.equipment.pojo.Employment;
import com.its.equipment.service.EmploymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/equipment")
public class EquipmentController {
    //依赖注入业务层属性
    @Autowired
    private EmploymentService employmentService;

    //新增设备
    @PostMapping("/add")
    public BaseResult addEquipment(@RequestBody Employment employment){
        return BaseResult.ok(employmentService.addEquipmentService(employment));
    }

    //删除设备
    @DeleteMapping("/delete")
    public BaseResult deleteEquipment(Integer equipmentId){
        return BaseResult.ok(employmentService.delEquipmentService(equipmentId));
    }

    //修改设备信息
    @PutMapping("/update")
    public BaseResult updateEquipment(@RequestBody Employment employment){
        return BaseResult.ok(employmentService.updateEquipmentService(employment));
    }

    //根据设备Id查询设备信息
    @GetMapping("/findById")
    public BaseResult selectEquipmentById(Integer equipmentId){
        return BaseResult.ok(employmentService.selectEquipmentById(equipmentId));
    }

    //根据设备名称查询设备信息
    @GetMapping("/findByName")
    public BaseResult selectEquipmentByName(String equipmentName){
        return BaseResult.ok(employmentService.selectEquipment(equipmentName));
    }

    //分页查询所有设备信息
    @GetMapping("/search")
    public BaseResult getAllEquipment(Integer page,Integer size){
        return BaseResult.ok(employmentService.getAllEquipment(page, size));
    }
}
